package 设计模式.工厂模式;

import com.sun.org.apache.bcel.internal.generic.RETURN;

/**
 * 汽车工厂
 *
 * @author zhoujie
 * @date 2020-07-31
 */
public enum CarFactory {
    //定义工厂类能生产汽车的类型
    FordCar, BuickCar;

    //生产汽车
    public Car createCar() {
        switch (this) {
            case FordCar:
                return new FordCar();
            case BuickCar:
                return new BuickCar();
            default:
                throw new AssertionError("无效参数");
        }
    }

    public static Car of(CarFactory car) {
        if (car == FordCar) {
            return new FordCar();
        } else if (car == BuickCar) {
            return new BuickCar();
        } else {
            throw new AssertionError("无效参数");
        }
    }
}
